package HallCallStrategy;

import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;

import Dispatcher.ElevatorStatus;

public class EasyHallCallStrategy implements HallCallStrategy {
	
	public EasyHallCallStrategy() {
		super();
	}

	@Override
	public int getBestElevator(int requestedFloor, int direction,
			ConcurrentHashMap<Integer, ElevatorStatus> status) {
		//if there is just one elevator, return its index
		if (status.size() == 1) {
			return 1;
		}
		
		//if any elevator is free, choose it
		for (int i : status.keySet()) {
			if (status.get(i).getState() == 1) {
				return i;
			}
		}
		
		//else choose a random elevator
		if (status.size() > 0) {
			Random generator = new Random();
			return generator.nextInt(status.size());
		}
		
		return 0;
	}

}
